﻿Imports System.Data
Imports System.Data.OleDb

Public Class DAL_ThemCauHoiChoBoDe

    Public conn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\10650_000\Desktop\ltudql1-doan\Database\Database.mdb"

    Public Function LoadCauHoiTrongNganHangCauHoi() As DataTable

        Dim strSQL As String = "Select macauhoi as Mã, noidung as Nội_dung_câu_hỏi from cauhoi"

        Dim con As New OleDbConnection(conn)

        Dim da As New OleDbDataAdapter(strSQL, con)

        Dim dt As New DataTable

        da.Fill(dt)

        Return dt

    End Function

    Public Function LoadCauHoiChoBoDe(ByVal TXTMABODE As String) As DataTable

        Dim StrSQL As String = "SELECT MaBoDe,MaCauHoi FROM CAUHOICHOBODE WHERE MaBoDe = '" & TXTMABODE & "' "

        Dim con As New OleDbConnection(conn)

        Dim da As New OleDbDataAdapter(StrSQL, con)

        Dim dt As New DataTable

        da.Fill(dt)

        Return dt


    End Function

    Public Sub ThemCauhoiVaoBangCAUHOICHOBODE(ByVal mabode As String, ByVal macauhoi As String)

        Dim StrSQL As String = " Insert into CAUHOICHOBODE (mabode,macauhoi) values (@mabode,@macauhoi)"

        Dim con As New OleDbConnection(conn)

        Dim cmd As New OleDbCommand(StrSQL, con)

        cmd.Parameters.Add("@mabode", OleDbType.VarChar).Value = mabode

        cmd.Parameters.Add("@macauhoi", OleDbType.VarChar).Value = macauhoi

        con.Open()

        cmd.ExecuteNonQuery()

        con.Close()


    End Sub

    Public Sub XoaNoiDungTrongBangTam()

        Dim StrSQL As String = "delete * from tabletemp"

        Dim con As New OleDbConnection(conn)

        Dim cmd As New OleDbCommand(StrSQL, con)

        con.Open()

        cmd.ExecuteNonQuery()

        con.Close()

    End Sub

    Public Sub XoaCauHoiTrongBoDe(ByVal MACAUHOI As String)

        Dim StrSQL As String = "delete * from CAUHOICHOBODE where MACAUHOI = @MACAUHOI"

        Dim con As New OleDbConnection(conn)

        Dim cmd As New OleDbCommand(StrSQL, con)

        cmd.Parameters.Add("@MACAUHOI", OleDbType.VarChar).Value = MACAUHOI

        con.Open()

        cmd.ExecuteNonQuery()

        con.Close()

    End Sub

    Public Function LoadCauHoiTrongNganHangCauHoiTheoMucDO(ByVal mucdo As String) As DataTable

        Dim strSQL As String = "Select macauhoi as Mã, noidung as Nội_dung_câu_hỏi from cauhoi where MucDo = '" & mucdo & "'"

        Dim con As New OleDbConnection(conn)

        Dim da As New OleDbDataAdapter(strSQL, con)

        Dim dt As New DataTable

        da.Fill(dt)

        Return dt

    End Function

End Class

